package cn.stylefeng.guns.modular.price.controller;

import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.price.entity.Price;
import cn.stylefeng.guns.modular.price.model.params.PriceParam;
import cn.stylefeng.guns.modular.price.service.PriceService;
import cn.stylefeng.roses.core.base.controller.BaseController;
import cn.stylefeng.roses.kernel.model.response.ResponseData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;


/**
 * 价格表控制器
 *
 * @author liuqiang
 * @Date 2020-02-10 13:17:20
 */
@RestController
@RequestMapping("/price")
public class PriceController extends BaseController {

    @Autowired
    private PriceService priceService;


    /**
     * 新增接口
     *
     * @author liuqiang
     * @Date 2020-02-10
     */
    @PostMapping("/addItem")
    public ResponseData addItem(@RequestBody PriceParam priceParam) {
        this.priceService.add(priceParam);
        return ResponseData.success();
    }

    /**
     * 编辑接口
     *
     * @author liuqiang
     * @Date 2020-02-10
     */
    @PostMapping("/editItem")
    public ResponseData editItem(@RequestBody PriceParam priceParam) {
        this.priceService.update(priceParam);
        return ResponseData.success();
    }

    /**
     * 删除接口
     *
     * @author liuqiang
     * @Date 2020-02-10
     */
//    @RequestMapping("/delete")
//    @ResponseBody
    public ResponseData delete(PriceParam priceParam) {
        this.priceService.delete(priceParam);
        return ResponseData.success();
    }

    /**
     * 查看详情接口
     *
     * @author liuqiang
     * @Date 2020-02-10
     */
    @GetMapping("/detail")
    public ResponseData detail(PriceParam priceParam) {
        Price detail = this.priceService.getById(priceParam.getId());
        return ResponseData.success(detail);
    }

    /**
     * 查询列表
     *
     * @author liuqiang
     * @Date 2020-02-10
     */
    @GetMapping("/list")
    public LayuiPageInfo list(PriceParam priceParam) {
        return this.priceService.findPageBySpec(priceParam);
    }

}


